package com.leyou.item.controller;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 根据id查询分类
     * @param id 分类id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> findById(@PathVariable("id")Long id)
    {
        return ResponseEntity.ok(categoryService.findById(id));
    }

    /**
     * 根据id集合查询出分类的集合
     * @param ids id集合
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(@RequestParam("ids") List<Long> ids)
    {
        return ResponseEntity.ok(categoryService.queryCategoryByIds(ids));
    }

    /**
     * 根据父类目录id查询子分类
     * @param pid 父类目录id
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByParentId(@RequestParam("pid") Long pid)
    {
        return ResponseEntity.ok(categoryService.queryCategoryByParentId(pid));
    }


    /**
     * 根据品牌id查询商品分类的集合
     * @param id 品牌id
     * @return
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByBrandId(@RequestParam("id") Long id)
    {
        return ResponseEntity.ok(categoryService.queryBrandById(id));
    }

}
